package com.btex.app.treaty;

import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.btex.app.MyApplication;
import com.btex.app.R;
import com.btex.app.entity.DealInfo;
import com.btex.app.tools.Tools;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

/**
 * @author zy zhangyi <zhangyi, 1104745049@QQ.com
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/10/20
 * @time 上午11:04
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */

public class DealAdapter extends BaseQuickAdapter<DealInfo.DataBean.TradeListsBean, BaseViewHolder> {

    private String mPric = "4";
    private String mValue = "4";
    private String mContract_value = "1";

    public DealAdapter() {
        super(R.layout.item_deal_adapter);
    }

    private String mDanwei = "";
    private String mIszhen = "11";

    @Override
    protected void convert(BaseViewHolder helper, DealInfo.DataBean.TradeListsBean item) {


        Log.i("ekjwfkefwiuehf", mPric + "=====" + mValue);

        View view = helper.getView(R.id.item_entrust_history_view_type);
        TextView item_treaty_history_tv_entrust_name = helper.getView(R.id.item_treaty_history_tv_entrust_name);
        TextView item_treaty_tv_entrust_history_time = helper.getView(R.id.item_treaty_tv_entrust_history_time);
        TextView item_treaty_tv_entrust_history_diss = helper.getView(R.id.item_treaty_tv_entrust_history_diss);
        TextView item_treaty_tv_entrust_history_type = helper.getView(R.id.item_treaty_tv_entrust_history_type);
        TextView item_treaty_tv_entrust_history_number = helper.getView(R.id.item_treaty_tv_entrust_history_number);
        TextView item_treaty_tv_entrust_history_price = helper.getView(R.id.item_treaty_tv_entrust_history_price);
        TextView item_treaty_tv_entrust_history_price_type = helper.getView(R.id.item_treaty_tv_entrust_history_price_type);
        TextView item_treaty_tv_entrust_chengjiao_history_price_type = helper.getView(R.id.item_treaty_tv_entrust_chengjiao_history_price_type);
        TextView item_treaty_tv_entrust_chengjiao_history_price = helper.getView(R.id.item_treaty_tv_entrust_chengjiao_history_price);
        TextView item_treaty_tv_entrust_history_chengjiao_shuliang = helper.getView(R.id.item_treaty_tv_entrust_history_chengjiao_shuliang);
        TextView item_treaty_tv_entrust_history_bao_cang = helper.getView(R.id.item_treaty_tv_entrust_history_bao_cang);
        TextView item_treaty_tv_entrust_chengjiao_history_jiage = helper.getView(R.id.item_treaty_tv_entrust_chengjiao_history_jiage);
        TextView item_treaty_tv_entrust_chengjiao_shouxufei = helper.getView(R.id.item_treaty_tv_entrust_chengjiao_shouxufei);
        TextView item_treaty_tv_entrust_history_ganggan_two = helper.getView(R.id.item_treaty_tv_entrust_history_ganggan_two);


        TextView item_treaty_tv_entrust_history_ganggan = helper.getView(R.id.item_treaty_tv_entrust_history_ganggan);
        TextView item_treaty_tv_entrust_history_duokong = helper.getView(R.id.item_treaty_tv_entrust_history_duokong);
        item_treaty_tv_entrust_history_ganggan.setVisibility(View.VISIBLE);
        item_treaty_tv_entrust_history_duokong.setVisibility(View.VISIBLE);
        item_treaty_tv_entrust_history_ganggan_two.setVisibility(View.VISIBLE);

        item_treaty_tv_entrust_chengjiao_shouxufei.setText(item.getTrade_fee() + "\t" + "\t" + mDanwei);

        String type = item.getType();
        if (type.equals("limit")) {
            item_treaty_tv_entrust_history_type.setText(R.string.heyue_xianjia);
        } else {
            item_treaty_tv_entrust_history_type.setText(R.string.heyue_shijia);
        }


        String order_price1 = item.getOrder_price();
        String num = item.getNum();
        String rest_num = item.getRest_num();
        String leverage = item.getLeverage();

        Log.i("weifjwoiejofw", leverage);


        String is_adl = item.getIs_adl();

        String is_liquidation = item.getIs_liquidation();

        if (!TextUtils.isEmpty(is_liquidation)) {


            if ("1".equals(is_liquidation)) {

                item_treaty_tv_entrust_history_bao_cang.setVisibility(View.VISIBLE);
                item_treaty_tv_entrust_history_bao_cang.setText("强制平仓");
                item_treaty_tv_entrust_history_bao_cang.setBackgroundColor(MyApplication.getContextObject().getResources().getColor(R.color.red));
            } else {

                item_treaty_tv_entrust_history_bao_cang.setVisibility(View.GONE);


                if (!TextUtils.isEmpty(is_adl)) {
                    if (is_adl.equals("1")) {

                        item_treaty_tv_entrust_history_bao_cang.setVisibility(View.VISIBLE);
                        item_treaty_tv_entrust_history_bao_cang.setText("自动减仓");
                        item_treaty_tv_entrust_history_bao_cang.setBackgroundColor(MyApplication.getContextObject().getResources().getColor(R.color.new_gray));
                    } else {

                        item_treaty_tv_entrust_history_bao_cang.setVisibility(View.GONE);
                    }
                } else {

                }

            }

        }


        if (!TextUtils.isEmpty(is_adl)) {
            if (is_adl.equals("1")) {

                item_treaty_tv_entrust_history_bao_cang.setVisibility(View.VISIBLE);
                item_treaty_tv_entrust_history_bao_cang.setText("自动减仓");
                item_treaty_tv_entrust_history_bao_cang.setBackgroundColor(MyApplication.getContextObject().getResources().getColor(R.color.new_gray));
            } else {

                item_treaty_tv_entrust_history_bao_cang.setVisibility(View.GONE);

                if ("1".equals(is_liquidation)) {

                    item_treaty_tv_entrust_history_bao_cang.setVisibility(View.VISIBLE);
                    item_treaty_tv_entrust_history_bao_cang.setText("强制平仓");
                    item_treaty_tv_entrust_history_bao_cang.setBackgroundColor(MyApplication.getContextObject().getResources().getColor(R.color.red));
                } else {

                    item_treaty_tv_entrust_history_bao_cang.setVisibility(View.GONE);

                }
            }
        } else {

        }


//        设置杠杆
        String is_cross = item.getIs_cross();
        if ("1".equals(is_cross)) {
//            全仓
            item_treaty_tv_entrust_history_ganggan.setText(leverage + "X" + ")");
            item_treaty_tv_entrust_history_ganggan_two.setText(R.string.heyue_quancang_k);

        } else {
            item_treaty_tv_entrust_history_ganggan.setText(leverage + "X" + ")");
            item_treaty_tv_entrust_history_ganggan_two.setText(R.string.zhucang_k);
        }
//        item_treaty_tv_entrust_history_ganggan.setText("(" + leverage + "X" + ")");


        item_treaty_tv_entrust_history_chengjiao_shuliang.setText(R.string.heyue_chengjiao_number);
        item_treaty_tv_entrust_history_diss.setVisibility(View.INVISIBLE);

        String ctime = item.getCtime();
        String contract_symbol = item.getContract_symbol();
        String price = item.getPrice();
        String order_price = item.getOrder_price();
        String trade_info = item.getTrade_info();


        double abs = Math.abs(Double.valueOf(num));
        String s = String.valueOf(abs);


        Log.i("weifjowjfew", mIszhen);
//        成交价值
        if (mIszhen.equals("1")) {

            Double Doubleprice1 = Double.valueOf(price);
            Double Doublenumber = Double.valueOf(s);
            double v1 = Doublenumber / Doubleprice1;
            String trim = Tools.round(v1 * Double.valueOf(mContract_value), Integer.valueOf(mValue)).toString().trim();
            item_treaty_tv_entrust_chengjiao_history_price.setText(trim + "\t" + "\t" + mDanwei);
        } else {

            Double Doubleprice1 = Double.valueOf(price);
            Double Doublenumber = Double.valueOf(s);
            double v1 = Doublenumber * Doubleprice1;
            String trim = Tools.round(v1 * Double.valueOf(mContract_value), Integer.valueOf(mValue)).toString().trim();
            item_treaty_tv_entrust_chengjiao_history_price.setText(trim + "\t" + "\t" + mDanwei);

        }

//        委托价格/成交价格
        if (Double.valueOf(item.getOrder_price()) == 0) {

            String trim = Tools.round(Double.valueOf(price), Integer.valueOf(mPric)).toString().trim();
            item_treaty_tv_entrust_history_price.setText(mContext.getString(R.string.heyue_shijia));
            item_treaty_tv_entrust_chengjiao_history_jiage.setText(trim);

        } else {

            String trim = Tools.round(Double.valueOf(price), Integer.valueOf(mPric)).toString().trim();
            String order = Tools.round(Double.valueOf(order_price1), Integer.valueOf(mPric)).toString().trim();
            item_treaty_tv_entrust_history_price.setText(order);
            item_treaty_tv_entrust_chengjiao_history_jiage.setText(trim);
        }


        if (trade_info.equals("buy")) {

            item_treaty_tv_entrust_history_duokong.setText(R.string.heyue_duo);
//            item_treaty_tv_entrust_history_duokong.setTextColor(MyApplication.getContextObject().getResources().getColor(R.color.bg_green));
            view.setBackgroundResource(R.color.bg_green);
            item_treaty_tv_entrust_history_price.setTextColor(MyApplication.getContextObject().getResources().getColor(R.color.bg_green));
        } else {

            item_treaty_tv_entrust_history_duokong.setText(R.string.heyue_kong);
//            item_treaty_tv_entrust_history_duokong.setTextColor(MyApplication.getContextObject().getResources().getColor(R.color.red));
            view.setBackgroundResource(R.color.red);
            item_treaty_tv_entrust_history_price.setTextColor(MyApplication.getContextObject().getResources().getColor(R.color.red));
        }


//        市场名称
        item_treaty_history_tv_entrust_name.setText(contract_symbol);
        String timedate = Tools.timedate(ctime);

        double v = Double.parseDouble(num) - Double.parseDouble(rest_num);
        item_treaty_tv_entrust_history_number.setText(num);

//        时间
        item_treaty_tv_entrust_history_time.setText(timedate);


    }

    public void setDanwei(String danwei) {

        mDanwei = danwei;
    }


    public void setIszhen(String iszhen) {

        mIszhen = iszhen;
    }


    public void SetNumber(String price, String value) {

        mPric = price;
        mValue = value;
    }


    public void setContractValue(String contract_value) {

        mContract_value = contract_value;
    }


}
